<template>
  <div class="app-container">
    <div class="boxlaw">
      <div class="title">
        <h1>{{ title }}</h1>
      </div>

      <ul>
        <li v-for="(item, index) in detailList" :key="index">
          <template v-if="item.type === '1'">
            <!-- <p
              :class="{ haveHistory: item.history !== undefined }"
              v-for="(subIten, index) in item.content"
              :key="index"
            >
              <Reader :obj="subIten"></Reader>
            </p> -->
            <Reader
              :class="{ haveHistory: item.history !== undefined }"
              v-for="(subIten, index) in item.content"
              :key="index"
              :obj="subIten"
            ></Reader>
            <div class="lawUpdate" v-if="item.history">
              <div>
                <h1 style="margin-right: 20px">法规更新</h1>
                <span class="update-time"
                  >更新日期：{{ item.updatedTime || item.createTime }}</span
                >
              </div>
              {{ item.history }}
            </div>
          </template>
          <template v-else>
            <el-image
              style="width: 500px"
              :src="item.content"
              :preview-src-list="[item.content]"
            >
            </el-image>
          </template>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import ComCard from "../../../../components/comCard.vue";
import { getLawInfoApi } from "@/wss/api/doc/law.js";
import { getLawUpdateLstApi } from "@/wss/api/lawUpdate";
import Reader from "@/wss/components/reader.vue";

// import { getdocGetTypeApi } from "@/wss/api/ContentSupervision";

export default {
  components: { ComCard, Reader },
  data() {
    return {
      detailList: [],
      title: "",
    };
  },
  mounted() {
    if (this.$route.query.esId) {
      this.getLawInfoApiMet({ id: this.$route.query.esId });
    } else {
      this.getLawInfoApiMet({ id: this.$route.query.id });
    }
  },
  methods: {
    // 获取更新记录并且改造数据解构
    async getLawUpdateLstFn() {
      let { rows, code } = await getLawUpdateLstApi({
        docId: this.$route.query.docId,
      });

      // 是否有更新记录
      if (!rows.length) {
        return;
      }
      let arr = [];
      if (code === 200) {
        this.detailList.map((item) => {
          rows.forEach((i) => {
            // 分解id
            if (item.idStr == i.updateId.split("_")[1]) {
              item.history = i.beforeText;
              item.content = [];
              item.createTime = i.createTime;
              item.updatedTime = i.updatedTime;
              item.content.push(i.afterText);
              arr.push(item);
            } else {
              arr.push(item);
            }
          });
        });
      }

      this.detailList = arr;
    },
    // //四大类接口
    // async getdocGetTypeFn() {
    //   let result = await getdocGetTypeApi({ type: "法规" });
    //   console.log(result, "法规详细");
    // },
    async getLawInfoApiMet(id) {
      let result = await getLawInfoApi(id).then((res) => res);
      console.log(result);
      if (result.code == 200 && result.data) {
        this.title = result.data.name;
        this.detailList = result.data.info;
        console.log(this.detailList, "detailist");
        // 有docId再查询更新记录
        if (this.$route.query.docId) {
          this.getLawUpdateLstFn();
        }
      } else {
        this.title = "目前还没有数据";
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  background-color: #f5f5f5;
  .boxlaw {
    padding: 10px;
    background-color: #ffffff;
  }

  .haveHistory {
    background-color: #fff0c2;
  }
  .lawUpdate {
    background-color: #f5f5f5;
    padding-left: 20px;
    div {
      display: flex;
      align-items: center;
    }
    // font-family: "MicrosoftYaHei", "Microsoft YaHei";
    // font-weight: 400;
    // font-style: normal;
    // font-size: 20px;
    // color: #e37709;
    .update-time {
      font-size: 13px;
    }
  }

  .title {
    text-align: center;
    font-family: "MicrosoftYaHei", "Microsoft YaHei";
    font-weight: 400;
    font-style: normal;
    font-size: 20px;
    color: #e37709;
  }
  ul {
    padding: 0px;

    li {
      list-style: none;
      margin: 32px 0px;
      font-size: 16px;
      font-family: "PingFangSC-Regular", "PingFang SC";
      span {
        font-family: "PingFangSC-Regular", "PingFang SC";
      }
      img {
        height: 200px;
        width: 200px;
      }
    }
  }
}
</style>